package com.llstudio.foodtogo.domain;

import java.time.LocalDateTime;

public class PlaceOrderServiceImpl implements PlaceOrderService {
    private PendingOrderRepository pendingOrderRepository;
    private RestaurantRepository restaurantRepository;

    public PlaceOrderServiceImpl(PendingOrderRepository pendingOrderRepository, RestaurantRepository restaurantRepository) {
        this.pendingOrderRepository = pendingOrderRepository;
        this.restaurantRepository = restaurantRepository;
    }

    @Override
    public PlaceOrderServiceResult updateDeliveryInfo(
            String pendingOrderId,
            Address deliveryAddress,
            LocalDateTime deliveryTime) {
        PendingOrder pendingOrder = pendingOrderRepository.findOrCreatePendingOrder(pendingOrderId);
        boolean success = pendingOrder.updateDeliveryInfo(restaurantRepository, deliveryAddress, deliveryTime);
        return new PlaceOrderServiceResult(success, pendingOrder);
    }
}

